//
//  BaseViewController.swift
//  Swift微博
//
//  Created by 白鹭 on 2017/3/4.
//  Copyright © 2017年 com.bailun91. All rights reserved.
//

import UIKit
class BaseViewController: UIViewController {

    lazy var vtView = visitorView.visitorView()
    
    // MARK 控制变量
    var isLogin = UserAccountViewModel.sharedUserAccountViewModel.isLogin
    
    override func viewDidLoad() {
        isLogin ? super.viewDidLoad() :setupNavigationItems()
    }
    
}


// MARK:- 设置UI界面
extension BaseViewController {

    func setupVisitorView(){
        
          view = vtView
       // 监听访客视图中`注册`和`登录`按钮的点击
        vtView.registerBtn.addTarget(self, action:#selector(BaseViewController.registerBtnClick), for: .touchUpInside)
        
        vtView.loginBtn.addTarget(self, action:#selector(BaseViewController.loginBtnClick), for: .touchUpInside)
    }
    
    func setupNavigationItems() {
        
        setupVisitorView()
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .plain, target: self, action: #selector(BaseViewController.registerBtnClick))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .plain, target: self, action: #selector(BaseViewController.loginBtnClick))
        
    }
    
}


// MARK:- 事件监听
extension BaseViewController {
    @objc fileprivate func registerBtnClick() {
        print("registerBtnClick")
    }
    
    @objc fileprivate func loginBtnClick() {
       
        let OAuthVC = OAuthViewController()
        
        let OAuthNav = UINavigationController(rootViewController: OAuthVC)
        
        present(OAuthNav, animated: true, completion: nil)
        
    }
}
